package com.itheima.itheima_health.controller.user;

import com.itheima.itheima_health.constant.MessageConstant;
import com.itheima.itheima_health.entity.Result;
import com.itheima.itheima_health.pojo.Setmeal;
import com.itheima.itheima_health.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检查组相关接口
 */
@RestController
@RequestMapping("/user/setmeal")
@Slf4j
@Api(tags = "套餐相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 查询全部套餐
     * @return
     */
    @PostMapping("/getAllSetmeal")
    @ApiOperation("查询全部套餐")
    @Cacheable(cacheNames = "setmeal",key = "'allSetmeal'")
    public Result getAllSetmeal(){
        log.info("查询全部套餐");
        List<Setmeal> setmealList = setmealService.getAllSetmeal();
        return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmealList);
    }

    /**
     * 查询套餐详情
     * @param id
     * @return
     */
    @PostMapping("/findById")
    @ApiOperation("查询套餐详情")
    /*@Cacheable(cacheNames = "setmealDetails",key = "#id")*/
    public Result findById(Integer id){
        log.info("查询套餐详情  套餐id:{}",id);
        Setmeal setmeal = setmealService.findById(id);
        return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }

}
